#!/usr/bin/env perl

use lib qw{../config ../lib/perl};
use strict;
use warnings;
use CGI;
use Cwd;
use Util;
use TRFLP;

my $cgi = new CGI;
my $dir = $cgi->param('dir');

Util::open_cgi_shell("Smoothing the raw data");

print "<b>&gt; cd $TRFLP::data_path/$dir</b>\n";

chdir "$TRFLP::data_path/$dir" or die "Couldn't call 'chdir $TRFLP::data_path/$dir', reason: $!";

foreach my $file ( grep /(sample|standard)$/, `ls .` ) {
  chomp $file;
  my $command;
  if ( $file =~ /standard$/ ) {
    #$command = "$TRFLP::bin/smooth-standard.m $file > $file.smooth";
    $command = "$TRFLP::bin/smooth.m $file > $file.smooth";
  }
  else {
    $command = "$TRFLP::bin/smooth.m $file > $file.smooth";
  }
  Util::run_task(*STDOUT, $command);
}

Util::close_cgi_shell();
